package com.pan.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pan.domain.Notice;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface NoticeDao extends BaseMapper<Notice> {
    //获取所有公告
    @Select("select * from tbl_notice")
    List<Notice> getAllNote();

    //获取delete为1的所有公告
    @Select("select `id`,`title`,`type`,`body`,`creator`,`create_time`,`update_time` from tbl_notice where `delete` = 1")
    List<Notice> getNotDeleteNotice();

    //按id查询delete为1的公告
    @Select("select `id`,`title`,`type`,`body`,`creator`,`create_time`,`update_time` from tbl_notice where `delete` = 1 and `id` = #{id}")
    Notice getByIdE(Integer id);

    //获取最新公告
    @Select("SELECT * FROM `tbl_notice` where `id` = (SELECT COUNT(*) FROM `tbl_notice`)")
    Notice getLastNotice();

    //操作员修改通知,配置文件
    Boolean updateByIdE(Notice notice);

    //逻辑删除通知
    @Update("update tbl_notice set `delete` = 0 where id = #{id} and `delete` = 1")
    Boolean LogicDelete(Integer id);
}
